import sys
print sys.path
sys.path.append(sys.path[0] + '/../lib')

from game import *
import unittest

import copy


class TestSequenceFunctions(unittest.TestCase):
	def setUp(self):
		return
		
	def testcardstatics(self):
		self.assertTrue(Card('A1') == Card('A1'))
		self.assertTrue(Card('A1') < Card('B1'))
		
		self.assertTrue(Card('A1').isColour())
		self.assertTrue(Card('B2').isColour())
		self.assertTrue(Card('C3').isColour())
		self.assertTrue(Card('D4').isColour())
		self.assertTrue(Card('D+2').isColour())
		self.assertFalse(Card('J').isColour())
		self.assertFalse(Card('+4').isColour())
		
		self.assertFalse(Card('A1').isSpecial())
		self.assertFalse(Card('B2').isSpecial())
		self.assertFalse(Card('C3').isSpecial())
		self.assertFalse(Card('D4').isSpecial())
		self.assertFalse(Card('D+2').isSpecial())
		self.assertTrue(Card('J').isSpecial())
		self.assertTrue(Card('+4').isSpecial())
		
		self.assertFalse(Card('A1').sameColour('B5'))
		self.assertTrue(Card('C2').sameColour('C5'))
		
		
	def testshuffle(self):
		deck = Deck()
		olddeck = copy.deepcopy(deck.content)
		
		deck.shuffle()
		self.assertEqual(len(olddeck), len(deck.content))
		self.assertEqual(sorted(olddeck), sorted(deck.content))
		self.assertNotEqual(olddeck, deck.content)
		
		
	def testdraw(self):
		deck = Deck()
		olddeck = copy.deepcopy(deck.content)
		
		deck.draw(5)
		self.assertEqual(len(olddeck) - 5, len(deck.content))
		
	def test_add_player(self):
		game = Game()
		for i in range(3): game.add_player(Player())
		
		self.assertEqual(3, len(game.players))
	
	
	def test_start(self):
		game = Game()
		for i in range(5): game.add_player(Player())
		olddeck = copy.deepcopy(game.stock.content)
		game.start()
		for p in game.players: self.assertEqual(7, len(p.cards))
			
		deck = []
		deck.extend(game.stock.content)
		deck.extend(game.discard.content)
		for p in game.players: deck.extend(p.cards)
		self.assertEqual(len(olddeck), len(deck))
		self.assertEqual(sorted(olddeck), sorted(deck))
	
if __name__ == '__main__':
	unittest.main()
